#include "mainbox.h"

mainBox::mainBox(QWidget *parent)
    : QWidget(parent)
{
    setMinimumSize(300,200);
    QAction *act = new QAction("最小化",this);
    mu->addAction(act);
    QAction *act2 = new QAction("当前窗口信息",this);
    mu->addAction(act2);
    QAction *act3 = new QAction("退出",this);
    mu->addAction(act3);
    QFont ft;
    ft.setBold(true);
    ft.setPointSize(16);
    mu->setFont(ft);
    mu->addSeparator();
    connect(act,&QAction::triggered,this,&QWidget::showMinimized);
    connect(act2,&QAction::triggered,this,[=](){
        qDebug() << this->screen()->size();
        QSize sz = this->screen()->size();
        ts->append(QString("%1").arg(sz.width()));
        ts->append(QString("%1").arg(sz.height()));
        ts->append(QString("%1").arg(this->width()));
        ts->append(QString("%1").arg(this->height()));
        //窗口原点取屏幕xy的一半减去窗体xy的一半
        int x = sz.width()/2 - this->width()/2;
        int y = sz.height()/2 -this->width()/2;
        this->move(x,y);
    });
    connect(act3,&QAction::triggered,this,&QApplication::exit);
    connect(ts,&QTextBrowser::textChanged,this,[=](){
        ts->moveCursor(QTextCursor::End);
    });
    gid->addWidget(ts);
}

mainBox::~mainBox()
{
}

void mainBox::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::RightButton)
    {
        mu->exec(cursor().pos());
    }
}

